package LeetCode刷题;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: Java_Study
 * @author: Xiaofan
 * @createTime: 2021-10-12 14:30
 * @description: Functions of this class is
 *
 **/
public class No验证二叉搜索树 {
    public static void main(String args[]){
        /**
         * 官方解法：
         * （递归法）
         * class Solution {
         *     public boolean isValidBST(TreeNode root) {
         *         return isValidBST(root, Long.MIN_VALUE, Long.MAX_VALUE);
         *     }
         *
         *     public boolean isValidBST(TreeNode node, long lower, long upper) {
         *         if (node == null) {
         *             return true;
         *         }
         *         if (node.val <= lower || node.val >= upper) {
         *             return false;
         *         }
         *         return isValidBST(node.left, lower, node.val) && isValidBST(node.right, node.val, upper);
         *     }
         * }
         *
         * （中序遍历法）
         * class Solution {
         *     public boolean isValidBST(TreeNode root) {
         *         Deque<TreeNode> stack = new LinkedList<TreeNode>();
         *         double inorder = -Double.MAX_VALUE;
         *
         *         while (!stack.isEmpty() || root != null) {
         *             while (root != null) {
         *                 stack.push(root);
         *                 root = root.left;
         *             }
         *             root = stack.pop();
         *               // 如果中序遍历得到的节点的值小于等于前一个 inorder，说明不是二叉搜索树
         *             if (root.val <= inorder) {
         *                 return false;
         *             }
         *             inorder = root.val;
         *             root = root.right;
         *         }
         *         return true;
         *     }
         * }
         */

    }

}